1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 import java.text.*;
30 import java.util.*;
31
32 public class Bug6609750 {
33
34 public static void main(String[] args) {
35 boolean error = false;
36
37 Locale defaultLocale = Locale.getDefault();
38 Locale.setDefault(Locale.US);
39
40 Date[] dates = {
41 new Date(9-1900, Calendar.JUNE, 12),
42 new Date(99-1900, Calendar.JUNE, 12),
43 new Date(999-1900, Calendar.JUNE, 12),
44 new Date(2009-1900, Calendar.JUNE, 12),
45 new Date(30009-1900, Calendar.JUNE, 12),
46 };
47
48 String[] patterns = {
49 "y", "yy", "yyy", "yyyy", "yyyyy", "yyyyyy"
50 };
51 String[][] expectedResults = {
52 {"9", "09", "009", "0009", "00009", "000009"},
53 {"99", "99", "099", "0099", "00099", "000099"},
54 {"999", "99", "999", "0999", "00999", "000999"},
55 {"2009", "09", "2009", "2009", "02009", "002009"},
56 {"30009", "09", "30009", "30009", "30009", "030009"},
57 };
58
59 SimpleDateFormat sdf = new SimpleDateFormat();
60 for (int dateNo = 0; dateNo < dates.length; dateNo++) {
61 Date date = dates[dateNo];
62 for (int patternNo = 0; patternNo < patterns.length; patternNo++) {
63 sdf.applyPattern(patterns[patternNo]);
64 String got = sdf.format(date);
65 if (!expectedResults[dateNo][patternNo].equals(got)) {
66 error = true;
67 System.err.println("Failed: Unexpected format result: " +
68 "Expected: \"" + expectedResults[dateNo][patternNo] +
69 "\", Got: \"" + got + "\" for date " + date +
70 " with pattern \"" + patterns[patternNo] + "\"");
71 }
72 }
73 }
74
75 Locale.setDefault(defaultLocale);
76 if (error) {
77 throw new RuntimeException("SimpleDateFormat.format() error.");
78 };
79 }
80
81 }